<?php
/**
* Base controller for backend
* @author Phong Quach
*/
class BackOfficeController extends ControllerBase
{
    /**
    * ID of current logged in user
    *
    * @var int
    */
    protected $userId;

    /**
    * Active menu
    *
    * @var string
    */
    public $ActiveMenu;

    public function __construct($id, $module = null){
        parent::__construct($id, $module);

        Yii::app()->theme = Settings::BO_THEME;
        Yii::app()->layout = Settings::DEFAULT_BO_LAYOUT;

        $this->userId = Yii::app()->user->Id;
        Yii::app()->user->loginUrl = array('/Site/login');
        if (!Yii::app()->user->isGuest) {
            if (!Yii::app()->user->isInRole(ApplicationUser::ROLE_ADMINISTRATORS))
                $this->redirect(array('/Site/login'));
        }
    }

    public function filters(){
        return array(
            'accessControl',
        );
    }

    public function accessRules(){
        return array(
            array(
                'allow',
                'actions' => array('login'),
                'users' => array('*')
            ),
            array(
                'allow',
                'users' => array('@')
            ),
            array(
                'deny',
                'users' => array('?'),
            ),
        );
    }

}
?>
